﻿Public Class MotorActivityUserControl
    Implements IRabbitActivityControl

#Region "Events"
    Public Event RemoveMotorActivity As EventHandler(Of EventArgs)
#End Region

#Region "Member Fields"
    Private _activity As NabaztagLib.Choreography.MotorRabbitActivity
#End Region

#Region "Properties"
    Private Property ActivityImpl() As NabaztagLib.Choreography.IRabbitActivity Implements IRabbitActivityControl.Activity
        Get
            Return Activity
        End Get
        Set(ByVal value As NabaztagLib.Choreography.IRabbitActivity)
            Activity = value
        End Set
    End Property

    Public Property Activity() As NabaztagLib.Choreography.MotorRabbitActivity
        Get
            If _activity Is Nothing Then
                _activity = New NabaztagLib.Choreography.MotorRabbitActivity
            End If
            Return _activity
        End Get
        Set(ByVal value As NabaztagLib.Choreography.MotorRabbitActivity)
            _activity = value
            RebindControls()
        End Set
    End Property
#End Region

#Region "Methods"
    Public Sub RebindControls()
        ActionMomentNumericUpDown.Value = Activity.ActionMoment
        If Activity.Ear = NabaztagLib.Choreography.MotorRabbitActivity.EarEnum.Left Then
            EarComboBox.SelectedItem = "Left"
        Else
            EarComboBox.SelectedItem = "Right"
        End If
        AngleNumericUpDown.Value = Activity.AngleOfEar
        If Activity.EarRotation = NabaztagLib.Choreography.MotorRabbitActivity.EarRotationEnum.Backward Then
            RotationComboBox.SelectedItem = "Backward"
        Else
            RotationComboBox.SelectedItem = "Foreward"
        End If
    End Sub
#End Region

#Region "Child Control Event Handlers"
    Private Sub ActionMomentNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ActionMomentNumericUpDown.ValueChanged
        Activity.ActionMoment = ActionMomentNumericUpDown.Value
    End Sub

    Private Sub EarComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EarComboBox.SelectedIndexChanged
        Select Case EarComboBox.SelectedItem
            Case "Left"
                Activity.Ear = NabaztagLib.Choreography.MotorRabbitActivity.EarEnum.Left
            Case Else
                Activity.Ear = NabaztagLib.Choreography.MotorRabbitActivity.EarEnum.Right
        End Select
    End Sub

    Private Sub AngleNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AngleNumericUpDown.ValueChanged
        Activity.AngleOfEar = AngleNumericUpDown.Value

    End Sub

    Private Sub RotationComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RotationComboBox.SelectedIndexChanged
        Select Case RotationComboBox.SelectedItem
            Case "Foreward"
                Activity.EarRotation = NabaztagLib.Choreography.MotorRabbitActivity.EarRotationEnum.Frontward
            Case Else
                Activity.EarRotation = NabaztagLib.Choreography.MotorRabbitActivity.EarRotationEnum.Backward
        End Select
    End Sub

    Private Sub RemoveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveToolStripMenuItem.Click
        RaiseEvent RemoveMotorActivity(Me, EventArgs.Empty)
    End Sub
#End Region


End Class
